#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int maxProfit(vector<int>& prices, int fee) {
        int n = prices.size();
        vector<vector<int>> as(n, vector<int>(2));
        as[0][0] = -prices[0];
        as[0][1] = 0;
        for (int i = 1; i < n; i++)
        {
            as[i][0] = max(as[i - 1][0], as[i - 1][1] - prices[i]);
            as[i][1] = max(as[i - 1][1], as[i - 1][0] + prices[i] - fee);
        }
        return as[n - 1][1];
    }
};